#pragma once
//headers
#include"global.h"
//Boost
//#include<boost/property_tree/ptree.hpp>
//#include<boost/property_tree/xml_parser.hpp>
//
using namespace std;

class msg
{
	string data;
public:
	msg(const string & data)
	{
		this->data=data;
	}
	string what()
	{
		return data;
	}
};
class simpleio
{
public:
	//output string(content) to file(filename)
	static void output(const string& filename,const string& content)
	{
		ofstream out(filename);
		if(!out.is_open())
			throw msg((filename+":cannot open file").c_str());
		out<<content;
		out.close();
	}
	static void input(const string& filename,string& content)
	{
		ifstream in(filename);
		if(!in.is_open())
			throw msg((filename+":cannot open file").c_str());
		in>>content;
		in.close();
	}
	static void error(const string& _msg,msg &e)
	{
		cerr<<_msg<<e.what()<<endl;
		//system("pause>nul");
		exit(-1);
	}	
};
/*
//This is for read setting.xml
class setting
{
private:
	void _Load(const string &filename);
	void _Save(const string &filename);
public:
	string logFile;
	string output_dir;
	string circutes_dir;
	//string lfsrs_dir;
	vector<string> circutes;
	//vector<string> lfsrs;
	setting(const string &filename);	
};
*/
template<typename _T>
class matrix
{
private:
	unique_ptr<_T[]> _Data;
	int _Row,_Colum;
	_T& _GetElement(int i,int j)
	{
		return _Data[i*_Row+j];
	}
public:
	matrix(int row,int colum)
	{
		_Row=row;
		_Colum=colum;
		_Data=move(unique_ptr<_T[]>(new _T[_Row*_Colum]));
	}
	_T& at(int i,int j)
	{
		if(i>=_Row||j>=_Colum)
			throw msg("matrix<_T>:invalid subscript");
		return _GetElement(i,j);
	}
	_T& operator()(int i,int j)
	{
		return _GetElement(i,j);
	}
};
/*
//С���
template<typename _T>
void _Decrease_heap(_T* first,_T* last,int position,const _T& value)
{
	if(position>last-first||value>first[position])
		throw msg("_Decrease_heap<_T>:invalid parameter");
	first[position]=value;
	int parent=(position+1)/2-1;
	while(parent>=0&&first[position]<first[parent])
	{
		swap(first[position],first[parent]);
		position=parent;
		parent=(position+1)/2-1;
	}
}

using boost::property_tree::ptree;
class table
{
private:
	ptree _Pt;
public:
	//table();
	void add(const tuple<string,int,int,double>& e);
	void save(const string& filename);
};

//
vector<vector<uint8_t>> merge_number(vector<vector<uint8_t>> data);
vector<uint8_t> merge_number(vector<vector<uint8_t>> data,vector<uint8_t> ref);


//Global varible
extern setting gSetting;
extern ofstream logfile;*/

